import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import { renderWithQiankun } from 'vite-plugin-qiankun/dist/helper'

import App from './App.vue'
import router from './router'
import { isQianKun } from './utils/isQianKun'

let app: any
const render = () => {
  createApp(App).use(router).mount('#app')
}

const qiankunInit = () => {
  renderWithQiankun({
    // qiankun的生命周期，挂载
    mount(props) {
      // 传递的值可以获取到了
      app = createApp(App)
      app.use(router)
      app.mount(
        props.container ? props.container.querySelector('#app') : document.getElementById('app'),
      )
    },
    // 应用加载
    bootstrap() {
      console.log('--bootstrap')
    },
    // 修改
    update(props) {
      console.log('--update', props)
    },
    // 销毁
    unmount() {
      console.log('--unmount')
      app?.unmount()
    },
  })
}
// 判断是否在qiankun环境下
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
isQianKun ? qiankunInit() : render()
